﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using SharepointSolutionInstaller.Utils;
using SharepointSolutionInstaller.Utils.Configuration;

namespace SharepointSolutionInstaller.Views
{

    public partial class EULAView : InstallerControl
    {
        public EULAView()
        {
            InitializeComponent();
            acceptCheckBox.CheckedChanged += new EventHandler(acceptCheckBox_CheckedChanged);
            this.Load += new EventHandler(EULAControl_Load);
            this.Title = Resources.CommonUIStrings.controlTitleLicense;
            this.SubTitle = Resources.CommonUIStrings.controlSubTitleLicense;
        }

        protected internal override void Open(InstallOptions options)
        {
            Form.btnNext.Enabled = acceptCheckBox.Checked;
        }

        private void EULAControl_Load(object sender, EventArgs e)
        {

            string filename = InstallConfiguration.EULA;
            if (!String.IsNullOrEmpty(filename))
            {
                try
                {
                    this.richTextBox.LoadFile(filename);
                    acceptCheckBox.Enabled = true;
                }

                catch (IOException)
                {
                    this.richTextBox.Lines = new string[] { "Error! Could not load " + filename };
                }
            }
        }

        private void acceptCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            Form.btnNext.Enabled = acceptCheckBox.Checked;
        }
    }
}
